package com.gopay.common.order.bankorder.trade;

import org.apache.commons.lang3.StringUtils;

import com.gopay.common.constants.bank.BankConstants;
import com.gopay.common.constants.bank.BisBankBusinessProd;
import com.gopay.common.constants.bank.BisBankInterfaceChannel;
import com.gopay.common.domain.cps.CpsGenMainOrder;

public class InitialSpringBeanName {
    /**
     * 获取SPRING加载的BeanName
     * 
     * <pre>
     * BeanName规范:银行编码-交易类型，如TBANK-B2B
     * </pre>
     * 
     * @param bank
     *            银行编码
     * @param payChannel
     *            支付渠道
     * @return
     */
    public static String getBeanName(CpsGenMainOrder mainOrder) {
        String beanSuffix = TradeType.getOrderTrandType(mainOrder.getPayChannel());
        String beanName = mainOrder.getOutStlmId() + "-" + beanSuffix;
        return beanName;
    }
    
    /**
     * 银企直连BeanName
     * @param bankCode
     * @return
     */
    public static String getBcdlBeanName(String bankCode) {
    	if(StringUtils.equals(bankCode, BankConstants.BANK_LOGO_SDB)){
    		bankCode = BankConstants.BANK_LOGO_PAB;
    	}
    	String beanName = bankCode + "-BCDL";
    	return beanName;
    }

    
    /**
     * 获得平台外部清算机构代码
     * @param bankInterface 银行接口通道信息
     * @param bankBusProd 银行业务产品代码
     * @param bankCode 银行码
     * @return
     */
    public static String getOutStlmCd(String bankInterface, String bankBusProd, String bankCode){
    	if(BisBankBusinessProd._09.value.equals(bankBusProd)){
    		return bankCode;// 银企直连直接返回银行码
    	}
		if(BisBankBusinessProd._11.value.equals(bankBusProd)){
			BisBankInterfaceChannel c = BisBankInterfaceChannel.get(bankInterface);
			if (BisBankInterfaceChannel._18.value.equals(c.value)) {//个人WAP网银网联通道
				return BankConstants.BANK_LOGO_NUCCPAY;
			}
			return bankCode;// WAP网银直接返回银行码
		}
		if(BisBankBusinessProd._16.value.equals(bankBusProd)){
			return bankCode;// 扫码支付直接返回银行码
		}
		if(BisBankBusinessProd._17.value.equals(bankBusProd)){
			return bankCode;// app支付直接返回银行码
		}
		if(BisBankBusinessProd._18.value.equals(bankBusProd)){
			return bankCode;// 公众号支付直接返回银行码
		}
		if(BisBankBusinessProd._25.value.equals(bankBusProd)){
		    return bankCode;// 小额支付直接返回银行码
		}

    	if(StringUtils.isBlank(bankInterface)){
			return bankCode;
		}
    	BisBankInterfaceChannel c = BisBankInterfaceChannel.get(bankInterface);
    	switch(c){
		case _00:// 直连通道
			return bankCode;
		case _01:// 联动优势
			return BankConstants.BANK_LOGO_UMPAY;
		case _02:// 联通沃
			return BankConstants.BANK_LOGO_CUCCPAY;
		case _03:// 深圳快付通
			return BankConstants.BANK_LOGO_SZFAST;
		case _04:// 民生银联
			return BankConstants.BANK_LOGO_UNIONPAY;
		case _06:// 海南新生
			return BankConstants.BANK_LOGO_HNAPAY;
		case _07:// 联动优势无卡 
			return BankConstants.BANK_LOGO_UMPAY;
		case _08:// 银联代扣 
			return BankConstants.BANK_LOGO_UNIONPAY;
		case _09:// 易宝快捷 
			return BankConstants.BANK_LOGO_YEEPAY;
		case _10:// 首信易支付
			return BankConstants.BANK_LOGO_PAYEASE;	
		case _11:// 民生代扣
            return BankConstants.BANK_LOGO_CMBCADPAY; 
		case _12:// 银盛
            return BankConstants.BANK_LOGO_YSPAY;
		case _13:// 民生i支付
            return BankConstants.BANK_LOGO_IPAY;
		case _19:// 浦发代扣
            return BankConstants.BANK_LOGO_SPDBADPAY;
		case _20:// 平安跨行支付
            return BankConstants.BANK_LOGO_KHPAY;
		case _18://网联
		    return BankConstants.BANK_LOGO_NUCCPAY;
		default:
			return bankCode;
		}
    }

	/**
	 * 获得平台外部清算机构代码
	 * @param bankInterface 银行接口通道信息
	 * @param bankCode 银行码
	 * @return
	 */
	public static String getOutStlmCdForNucc(String bankInterface, String bankCode){
		if(StringUtils.isBlank(bankInterface)){
			return bankCode;
		}
		BisBankInterfaceChannel c = BisBankInterfaceChannel.get(bankInterface);
		switch(c){
			case _18://网联
				return BankConstants.BANK_LOGO_NUCCPAY;
			default:
				return bankCode;
		}
	}
}
